# coding=utf-8
import socket
import time
import requests
import hashlib
import json
import gzip
import StringIO
timeout = 5  # in seconds
socket.setdefaulttimeout(timeout)
url = "https://121.43.157.12:8443/peiwan-server/rest/users/login"
m2 = hashlib.md5()
m2.update("123456")
r = requests.get(url, params={
    "username": "1556586435018",
    "password": m2.hexdigest()
}, verify=False)
# r = requests.get(url, params={
#     "username": "15874168512",
#     "password": m2.hexdigest()
# }, verify=False)
session = json.loads(r.content)['extra']


i = 0
while 1:
    try:
        url2 = "https://121.43.157.12:8443/peiwan-server/rest/users/aroundPeiwan"
        r = requests.get(url2, params={
            "session": session,
            "offset": 0,
            "limit": 8
        }, verify=False)
        f = StringIO.StringIO(r.content)
        gziper = gzip.GzipFile(fileobj=f)
        data = gziper.read()
        print 'status:' + str(json.loads(data)['status'])
        i += 1
        print str(i) + "#"
    except Exception, e:
        print e
        time.sleep(5)
